package com.sophialex.health.record.ui.pregnant;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.part.ViewPart;

import com.sophia.common.xmlbean.pojo.postpartum42check.Postpartum42DayCheckXMLPojo;
import com.sophialex.health.record.Messages;
import com.sophialex.health.record.common.bind.swt.annotations.AnnotionProcessor;
import com.sophialex.health.record.common.bind.swt.annotations.ListPathBindTo;
import com.sophialex.health.record.common.draw.DesignUI;
import com.sophialex.health.record.common.draw.UIFormAttachment;
import com.sophialex.health.record.common.utils.ImageUtil;

/**
 * 产后42天检查记录
 * <p>Title:Health</p>
 * <p>PostpartumUI</p>
 * 
 * Alex May 26, 2011 9:48:19 PM create
 * @author <a href='wanghao924@126.com'>Alex</a>
 * QQ: 873987060;
 * @version 1.0
 */
public abstract class Postpartum42DayCheckUI extends ViewPart {
	public static final String ID = "com.sophialex.health.record.ui.pregnant.Postpartum42DayCheckUI";

	private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());

    protected Label lb_fssj,lb_fsr,lb_ybqk,lb_tw,lb_xy,lb_rf,lb_wy,lb_yd,lb_gj,lb_zg,lb_fj,lb_sk,lb_cfqt,lb_cl,lb_cfbjzd,lb_zj;
	
    protected AnnotionProcessor ap = new AnnotionProcessor(this);
    
    /**
     * 产后42天检查XML类
     */
    protected Postpartum42DayCheckXMLPojo postpartum42DayCheck = new Postpartum42DayCheckXMLPojo();
	
    @ListPathBindTo(UIPropName = "selection", beanPath = "postpartum42DayCheck.checkTime.value")
	protected DateTime date_fssj; //检查日期
    
    @ListPathBindTo(beanPath = "postpartum42DayCheck.doctorName.value")
	protected Text txt_fsr; // 检查者
	
//    @ListPathBindTo(beanPath = "postpartum42DayCheck.generalCase.value")
//	protected Text txt_ybqk; //一般情况  产妇

    @ListPathBindTo(beanPath = "postpartum42DayCheck.bloodPressure.value")	
 	protected Text txt_xy; //血压 mmHg
	
    @ListPathBindTo(beanPath = "postpartum42DayCheck.breast.value")	
	protected Text txt_rf; //乳房
	
    @ListPathBindTo(beanPath = "postpartum42DayCheck.vulva.value")	
	protected Text txt_wy; //外阴
	
    @ListPathBindTo(beanPath = "postpartum42DayCheck.vagina.value")	
	protected Text txt_yd; //阴道
	
    @ListPathBindTo(beanPath = "postpartum42DayCheck.uterineNeck.value")	
	protected Text txt_gj; //宫颈
    
    @ListPathBindTo(beanPath = "postpartum42DayCheck.womb.value")	
	protected Text txt_zg; //子宫
	
    @ListPathBindTo(beanPath = "postpartum42DayCheck.affix.value")	
	protected Text txt_fj; //附件
	
    @ListPathBindTo(beanPath = "postpartum42DayCheck.wound.value")	
	protected Text txt_sk; //伤口
	
    @ListPathBindTo(beanPath = "postpartum42DayCheck.other.value")	
	protected Text txt_cfqt; //其他   
	
//	protected Text txt_cl; //处理
	
    @ListPathBindTo(beanPath = "postpartum42DayCheck.instruction.value")	
	protected Text txt_cfbjzd; //保健指导
	
    @ListPathBindTo(beanPath = "postpartum42DayCheck.referral.value")	
	protected Text txt_zj; //总结或转诊
     
	public Postpartum42DayCheckUI() {
	}

	private Composite composite_1;

	protected ToolItem toolItemEdit;

	protected ToolItem toolItemDel;

	protected ToolItem toolItemSave;

	protected ToolItem toolItemCancel;

	protected ToolItem toolItemAdd;

	protected ToolItem toolItemExit;
	
	protected Postpartum42DayCheckUIState viewstate = Postpartum42DayCheckUIState.ADD_VIEW;
	
	

	protected enum Postpartum42DayCheckUIState {
		ADD_VIEW, EDIT_VIEW, SHOW_VIEW;
	}

	/**
	 * Create contents of the view part.
	 * 
	 * @param parent
	 */
	@Override
	public void createPartControl(Composite parent) {
		Composite container = new Composite(parent, SWT.NONE);
		container.setLayout(new FormLayout());
		{
			composite_1 = new Composite(container, SWT.NONE);
			composite_1.setLayout(new FillLayout(SWT.HORIZONTAL));
			{
				FormData formData = new FormData();
				formData.height = 50;
				formData.right = new FormAttachment(100);
				formData.top = new FormAttachment(0);
				formData.left = new FormAttachment(0);
				composite_1.setLayoutData(formData);
			}
			{
				ToolBar toolBar = new ToolBar(composite_1, SWT.FLAT | SWT.NONE);
				toolBar.setBackgroundImage(ImageUtil.TBBJ);
				// {
				// toolItemAdd = new ToolItem(toolBar, SWT.NONE);
				//					toolItemAdd.setText(Messages.getString("RecordUI.0")); //$NON-NLS-1$
				// toolItemAdd.setImage(ImageUtil.add);
				// toolItemAdd.addSelectionListener(new SelectionAdapter() {
				// @Override
				// public void widgetSelected(SelectionEvent e) {
				// doAdd();
				// }
				// });
				// }
				{
					toolItemEdit = new ToolItem(toolBar, SWT.NONE);
					toolItemEdit.setText(Messages.getString("RecordUI.1")); //$NON-NLS-1$
					toolItemEdit.setImage(ImageUtil.edit);
					toolItemEdit.addSelectionListener(new SelectionAdapter() {
						@Override
						public void widgetSelected(SelectionEvent e) {
							doEdit();
						}
					});
				}
				{
					toolItemDel = new ToolItem(toolBar, SWT.NONE);
					toolItemDel.setText(Messages.getString("RecordUI.2")); //$NON-NLS-1$
					toolItemDel.setImage(ImageUtil.delete);
					toolItemDel.addSelectionListener(new SelectionAdapter() {
						@Override
						public void widgetSelected(SelectionEvent e) {
							doDel();
						}
					});
				}
				{
					@SuppressWarnings("unused")
					ToolItem toolItem = new ToolItem(toolBar, SWT.SEPARATOR);
				}
				{
					toolItemSave = new ToolItem(toolBar, SWT.NONE);
					toolItemSave.setText(Messages.getString("RecordUI.3")); //$NON-NLS-1$
					toolItemSave.addSelectionListener(new SelectionAdapter() {
						@Override
						public void widgetSelected(SelectionEvent e) {
							doSave();
						}
					});
					toolItemSave.setImage(ImageUtil.save);
				}

				{
					toolItemCancel = new ToolItem(toolBar, SWT.NONE);
					toolItemCancel.setText(Messages.getString("RecordUI.4")); //$NON-NLS-1$
					toolItemCancel.addSelectionListener(new SelectionAdapter() {
						@Override
						public void widgetSelected(SelectionEvent e) {
							doCancel();
						}
					});
					toolItemCancel.setImage(ImageUtil.cancel);
				}
				{
					toolItemExit = new ToolItem(toolBar, SWT.NONE);
					toolItemExit.setText(Messages.getString("RecordUI.6")); //$NON-NLS-1$
					toolItemExit.addSelectionListener(new SelectionAdapter() {
						@Override
						public void widgetSelected(SelectionEvent e) {
							doExit();
						}
					});
					toolItemExit.setImage(ImageUtil.exit);
				}
				/*
				 * { ToolItem toolItem = new ToolItem(toolBar, SWT.NONE);
				 * toolItem.setText(Messages.getString("RecordUI.5"));
				 * //$NON-NLS-1$ toolItem.setImage(ImageUtil.print);
				 * toolItem.addSelectionListener(new SelectionAdapter() {
				 * 
				 * @Override public void widgetSelected(SelectionEvent e) {
				 * doPrint(); } }); }
				 */
			}
		}

		{
			Composite composite = new Composite(container, SWT.NONE);
			{
				FormData formData = new FormData();
				formData.top = new FormAttachment(composite_1, 0);
				formData.bottom = new FormAttachment(100, -4);
				formData.right = new FormAttachment(composite_1, 0, SWT.RIGHT);
				formData.left = new FormAttachment(composite_1, 0, SWT.LEFT);
				composite.setLayout(new FillLayout(SWT.FILL));
				composite.setLayoutData(formData);

			}
			drawUI(composite);
		}
		initCombo();
		createActions();
		initializeToolBar();
		initializeMenu();

		this.setPartName(Messages.getString("Postpartum42DayCheck.Title")); //$NON-NLS-1$

	}

	// 绘制界面
	private void drawUI(Composite parent) {

		ScrolledComposite scrolledComposite = new ScrolledComposite(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
		toolkit.adapt(scrolledComposite);
		toolkit.paintBordersFor(scrolledComposite);
		scrolledComposite.setExpandHorizontal(true);
		scrolledComposite.setExpandVertical(true);
		
		ScrolledForm scrldfrmNewScrolledform = toolkit.createScrolledForm(scrolledComposite);
		toolkit.paintBordersFor(scrldfrmNewScrolledform);
		scrldfrmNewScrolledform.setText("   姓名：张三             个人档案编号：152877552142211");
		scrldfrmNewScrolledform.getBody().setLayout(new FormLayout());
		Label horLine =  new Label(scrldfrmNewScrolledform.getBody(), SWT.SEPARATOR | SWT.HORIZONTAL);
		FormData fd_horLine = new FormData();
		fd_horLine.top = new FormAttachment(0, 10);
		fd_horLine.left = new FormAttachment(2, 0);
		fd_horLine.right = new FormAttachment(100,-10);
		horLine.setLayoutData(fd_horLine);
		toolkit.adapt(horLine, true, true);
		
		
		//检查日期
		{
			lb_fssj = toolkit.createLabel(scrldfrmNewScrolledform.getBody(), "检查日期：", SWT.NONE);
			FormData fd_label = new FormData();
			fd_label.top = new FormAttachment(0, 35);
			fd_label.left = new FormAttachment(2, 0);
			lb_fssj.setLayoutData(fd_label);
			
			date_fssj = new DateTime(scrldfrmNewScrolledform.getBody(), SWT.BORDER | SWT.DROP_DOWN);
			FormData fd_txtNewText = new FormData();
			fd_txtNewText.right = new FormAttachment(lb_fssj, 166, SWT.RIGHT);
			fd_txtNewText.top = new FormAttachment(lb_fssj,-8,SWT.TOP);
			fd_txtNewText.bottom = new FormAttachment(lb_fssj,0,SWT.BOTTOM);
			fd_txtNewText.left = new FormAttachment(lb_fssj, 6);
			date_fssj.setLayoutData(fd_txtNewText);
			toolkit.adapt(date_fssj, true, true);
		}
		
		//检查者
		{
			lb_fsr = toolkit.createLabel(scrldfrmNewScrolledform.getBody(), "检查者：", SWT.NONE);
			FormData fd_label_fsr = new FormData();
			fd_label_fsr.left = new FormAttachment(date_fssj, 140);
			fd_label_fsr.top = new FormAttachment(lb_fssj,0,SWT.TOP);
			lb_fsr.setLayoutData(fd_label_fsr);
			
			txt_fsr = toolkit.createText(scrldfrmNewScrolledform.getBody(), "", SWT.NONE);
			FormData fd_fsr = new FormData();
			fd_fsr.top = new FormAttachment(date_fssj,0,SWT.TOP);
			fd_fsr.right = new FormAttachment(lb_fsr, 166, SWT.RIGHT);
			fd_fsr.left = new FormAttachment(lb_fsr, 6);
			txt_fsr.setLayoutData(fd_fsr);
		}
					
		// 访视情况
		UIFormAttachment fsqksectionUIAttachment = UIFormAttachment.getDefault(lb_fssj,12,0,true);
		Section fsqkSection = DesignUI.drawSection(toolkit, scrldfrmNewScrolledform, fsqksectionUIAttachment, "检查情况",false);
		Composite composite_fsqk = DesignUI.drawSectionComposite(toolkit, fsqkSection);
	
		List<Control[]> cfqkControlList = new ArrayList<Control[]>();
//		//一般情况
//		{
//			lb_ybqk = toolkit.createLabel(composite_fsqk, "               一般情况：", SWT.NONE);
//			txt_ybqk = toolkit.createText(composite_fsqk, "", SWT.NONE);
//			Control[] controls = {lb_ybqk,txt_ybqk};
//			cfqkControlList.add(controls);
//		}
		//血压 mmHg
		{
			lb_xy = toolkit.createLabel(composite_fsqk, "               血压：", SWT.NONE);
			txt_xy = toolkit.createText(composite_fsqk, "", SWT.NONE);
			Label li =  toolkit.createLabel(composite_fsqk, "mmHg", SWT.NONE);
			Control[] controls = {lb_xy,txt_xy,li};
			cfqkControlList.add(controls);
		}
		//乳房
		{
			lb_rf = toolkit.createLabel(composite_fsqk, "乳房：", SWT.NONE);
			txt_rf = toolkit.createText(composite_fsqk, "", SWT.NONE);
			Control[] controls = {lb_rf,txt_rf};
			cfqkControlList.add(controls);
		}
		//外阴
		{
			lb_wy = toolkit.createLabel(composite_fsqk, "外阴：", SWT.NONE);
			txt_wy = toolkit.createText(composite_fsqk, "", SWT.NONE);
			Control[] controls = {lb_wy,txt_wy};
			cfqkControlList.add(controls);
		}
		//阴道
		{
			lb_yd = toolkit.createLabel(composite_fsqk, "阴道：", SWT.NONE);
			txt_yd = toolkit.createText(composite_fsqk, "", SWT.NONE);
			Control[] controls = {lb_yd,txt_yd};
			cfqkControlList.add(controls);
		}
		//宫颈
		{
			lb_gj = toolkit.createLabel(composite_fsqk, "宫颈：", SWT.NONE);
			txt_gj = toolkit.createText(composite_fsqk, "", SWT.NONE);
			Control[] controls = {lb_gj,txt_gj};
			cfqkControlList.add(controls);
		}
		//子宫
		{
			lb_zg = toolkit.createLabel(composite_fsqk, "子宫：", SWT.NONE);
			txt_zg = toolkit.createText(composite_fsqk, "", SWT.NONE);
			Control[] controls = {lb_zg,txt_zg};
			cfqkControlList.add(controls);
		}
		//附件
		{
			lb_fj = toolkit.createLabel(composite_fsqk, "附件：", SWT.NONE);
			txt_fj = toolkit.createText(composite_fsqk, "", SWT.NONE);
			Control[] controls = {lb_fj,txt_fj};
			cfqkControlList.add(controls);
		}
		//伤口
		{
			lb_sk = toolkit.createLabel(composite_fsqk, "伤口：", SWT.NONE);
			txt_sk = toolkit.createText(composite_fsqk, "", SWT.NONE);
			Control[] controls = {lb_sk,txt_sk};
			cfqkControlList.add(controls);
		}
		//其他   (产妇)
		{
			lb_cfqt = toolkit.createLabel(composite_fsqk, "其他：", SWT.NONE);
			txt_cfqt = toolkit.createText(composite_fsqk, "", SWT.NONE);
			Control[] controls = {lb_cfqt,txt_cfqt};
			cfqkControlList.add(controls);
		}
//		//处理
//		{
//			lb_cl = toolkit.createLabel(composite_fsqk, "处理：", SWT.NONE);
//			txt_cl = toolkit.createText(composite_fsqk, "", SWT.NONE);
//			Control[] controls = {lb_cl,txt_cl};
//			cfqkControlList.add(controls);
//		}
		DesignUI.drawSecionContent(composite_fsqk, cfqkControlList,3,true,null);
			

		//保健指导
		{
			lb_cfbjzd = toolkit.createLabel(composite_fsqk, "保健指导：", SWT.NONE);
			FormData fd_cl = new FormData();
			fd_cl.top = new FormAttachment(lb_fj,40,SWT.TOP);
			fd_cl.right = new FormAttachment(lb_fj,0,SWT.RIGHT);
			lb_cfbjzd.setLayoutData(fd_cl);
			
			txt_cfbjzd = toolkit.createText(composite_fsqk, "", SWT.MULTI | SWT.V_SCROLL | SWT.WRAP);
			FormData fd_txt_cl = new FormData();
			fd_txt_cl.right = new FormAttachment(txt_cfqt, 0, SWT.RIGHT);
			fd_txt_cl.top = new FormAttachment(lb_cfbjzd,0, SWT.TOP);
			fd_txt_cl.bottom = new FormAttachment(lb_cfbjzd,60,SWT.BOTTOM);
			fd_txt_cl.left = new FormAttachment(lb_cfbjzd, 6);
			txt_cfbjzd.setLayoutData(fd_txt_cl);
		}
			
		//总结或转诊	
		{
			lb_zj = toolkit.createLabel(composite_fsqk, "总结或转诊：", SWT.NONE);
			FormData fd_cl = new FormData();
			fd_cl.top = new FormAttachment(txt_cfbjzd,40,SWT.BOTTOM);
			fd_cl.right = new FormAttachment(lb_cfbjzd,0,SWT.RIGHT);
			lb_zj.setLayoutData(fd_cl);
			
			txt_zj = toolkit.createText(composite_fsqk, "", SWT.MULTI | SWT.V_SCROLL | SWT.WRAP);
			FormData fd_txt_cl = new FormData();
			fd_txt_cl.right = new FormAttachment(txt_cfqt, 0, SWT.RIGHT);
			fd_txt_cl.top = new FormAttachment(lb_zj,0, SWT.TOP);
			fd_txt_cl.bottom = new FormAttachment(lb_zj,60,SWT.BOTTOM);
			fd_txt_cl.left = new FormAttachment(lb_zj, 6);
			txt_zj.setLayoutData(fd_txt_cl);
		}	
		scrolledComposite.setContent(scrldfrmNewScrolledform);
		scrolledComposite.setMinSize(scrldfrmNewScrolledform.computeSize(SWT.DEFAULT, SWT.DEFAULT));
	}

	protected void doExport() {

	}

	protected void doExit() {
		getViewSite().getPage().hideView(this);
	}

	protected abstract void doCancel();

	protected abstract void doSave();

	protected abstract void doDel();

	protected abstract void doEdit();

	protected abstract void doAdd();

	protected abstract void doPrint();

	/**
	 * Create the actions.
	 */
	private void createActions() {

	}

	/**
	 * Initialize the toolbar.
	 */
	private void initializeToolBar() {
		@SuppressWarnings("unused")
		IToolBarManager toolbarManager = getViewSite().getActionBars().getToolBarManager();
	}

	/**
	 * Initialize the menu.
	 */
	private void initializeMenu() {
		@SuppressWarnings("unused")
		IMenuManager menuManager = getViewSite().getActionBars().getMenuManager();
	}

	public void initCombo() {
	}
    
	protected void setActionControl() {
		if(viewstate == Postpartum42DayCheckUIState.ADD_VIEW || viewstate == Postpartum42DayCheckUIState.EDIT_VIEW) {
			toolItemEdit.setEnabled(false);
			toolItemDel.setEnabled(false);
			toolItemCancel.setEnabled(true);
			toolItemSave.setEnabled(true);
	 
		} else if(viewstate == Postpartum42DayCheckUIState.SHOW_VIEW) {
			toolItemEdit.setEnabled(true);
			toolItemDel.setEnabled(true);
			toolItemCancel.setEnabled(false);
			toolItemSave.setEnabled(false);
 
 
		}

	}
	
}
